<template>
	<el-container>
		<el-aside>
		</el-aside>
		<el-container>
			<el-card shadow="hover" header="工作日志设置" style="width:100%">
				<el-form :model="form" :rules="rules" label-width="100px" label-position="left" ref="dialogForm">
					<el-form-item label="锁定时长">
						<el-input-number v-model="form.lockDay" placeholder="锁定时长" clearable></el-input-number>
						<div class="el-form-item-msg">最多能补前几天的工作日志</div>
					</el-form-item>
					<el-form-item label="是否默认共享">
						<el-radio-group v-model="form.shareStatus">
							<el-radio-button label="3">禁止</el-radio-button>
							<el-radio-button label="0">全体</el-radio-button>
							<el-radio-button label="1">本部门</el-radio-button>
							<el-radio-button label="2">指定</el-radio-button>
						</el-radio-group>
						<div class="el-form-item-msg">设置日志是否可分享或者是分享范围</div>
					</el-form-item>
					<el-form-item label="是否允许评论">
						<el-radio-group v-model="form.commStatus">
							<el-radio-button label="0">禁止</el-radio-button>
							<el-radio-button label="1">允许</el-radio-button>
						</el-radio-group>
						<div class="el-form-item-msg">开启或关闭日志的评论功能</div>
					</el-form-item>
					<el-form-item label="日志模版">
						<sc-editor v-model="form.template" placeholder="请输入" :height="400" clearable  style="width: 100%;"></sc-editor>
					</el-form-item>
				</el-form>
				<div style="width: 100%;text-align: center">
					<el-button type="primary" :loading="isSaveing" @click="submit()">确 定</el-button>
				</div>
			</el-card>
		</el-container>
		<el-aside>
		</el-aside>
	</el-container>
</template>

<script>
import {defineAsyncComponent} from "vue";
const scEditor = defineAsyncComponent(() => import('@/components/scEditor'));
export default {
	name: 'Work Diary Setting',
	components: {
		scEditor
	},
	data() {
		return {
			isSaveing:false,
			form: {
				lockDay: 0,
				shareStatus:"3",
				commStatus:"0",
				template:""
			},
			rules: {}
		}
	},
	mounted() {
		this.getDiaryConfig();
	},
	methods: {
		async getDiaryConfig(){
			var res = await this.$API.office.diary.getDiaryConfig.get();
			if (res.code == 200) {
				this.form = res.data;
			} else {
				this.$alert(res.message, "提示", {type: 'error'})
			}
		},
		submit() {
			this.$refs.dialogForm.validate(async (valid) => {
				if (valid) {
					this.isSaveing = true;
					var res = await this.$API.office.diary.setDiaryConfig.post(this.form);
					this.isSaveing = false;
					if (res.code == 200) {
						this.visible = false;
						this.$message.success("操作成功")
					} else {
						this.$alert(res.message, "提示", {type: 'error'})
					}
				}
			})
		}
	}
}
</script>

<style>
</style>
